﻿using Easy.Common.Results;
using Easy.Services.Dtos;
using Easy.Services.Interface;
using Microsoft.AspNetCore.Mvc;

namespace Easy.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HomeController(IUserService _userService,
        IInterService _interService,
        IDatabaseService _databaseService,
        IIOSService _iosService) : BaseController
    {
        readonly IUserService userService = _userService;

        readonly IInterService interService = _interService;

        readonly IDatabaseService databaseService = _databaseService;

        readonly IIOSService iosService = _iosService;


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public APIResult Data()
        {
            APIResult result = new();
            if (TokenModel == null)
            {
                result.Message = "登录信息失效";
                return result;
            }
            HomeDataDTO dataDTO = new()
            {
                EmployeeTotal = userService.GetTotal(),
                InterfaceAccessTotal = interService.GetTotal(),
                RegularEmployeeTotal = userService.GetTotal(u => u.FormOfEmployment == 1),
                EchartDbData = databaseService.GetStatistics(),
                EchartIosData = iosService.GetStatistics(),
                EchartInterData = interService.GetStatistics()
            };
            result.Data = dataDTO;
            result.Success = true;
            return result;
        }

    }
}
